package homework;

import java.util.Comparator;
import java.util.TreeSet;

/*
2.分析以下需求，并用代码实现：
	(1)定义一个员工类Employee，包含三个属性：姓名(String name)、年龄(int age)、工资(int salary)
	(2)创建5个对象装入TreeSet，按照工资从高到底排序输出结果(工资相同，按照年龄从低到高，工资和年龄都相同，
		按照姓名字典顺序排列，但是不能去重(姓名、年龄、工资都相同))
*/
public class Demo1 {
    public static void main(String[] args) {
        TreeSet<Employee>list = new TreeSet<>(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
               if(o1.getSalary()!=o2.getSalary()){
                    return o1.getSalary() -o2.getSalary();
                }else{
                    if(o1.getAge()==o2.getAge()){
                        int i = o1.getName().compareTo(o2.getName());
                    }else{
                        return o1.getAge()-o2.getAge();
                    }
                }
                return 1;
 /*               //主要条件
                int result =o1.getSalary()- o2.getSalary() ;
                //次要条件
                result = result == 0 ? o1.getAge() - o2.getAge() : result;
                result = result == 0? o1.getName().compareTo(o2.getName()) : result;
                return result;*/
            }
        });
        Employee e1 = new Employee("zhangsang",18,3500);
        Employee e2 = new Employee("lisi",18,4000);
        Employee e3 = new Employee("zhangsang",18,3500);
        Employee e4 = new Employee("dafei",38,3500);
        Employee e5 = new Employee("shiw",28,6000);
        list.add(e1);
        list.add(e2);
        list.add(e3);
        list.add(e4);
        list.add(e5);
        for (Employee employee : list) {
            System.out.print(employee+"     ");
        }
        System.out.println();
    }
}
